home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-11-13 | 7.5 KB | 310 lines | [TEXT/AKu?] |
- property kasIdleSecs : 1
- property kasEyeSize : 66 -- Diameter of eye
- property kasIrisSize : round (kasEyeSize / 2) - 1 -- Diameter of iris
- property kasPupilSize : round (kasIrisSize / 4) -- Diameter of pupil
- property kasRadI : round (kasIrisSize / 2) -- Radius of iris
- property kasRadE : round (kasEyeSize / 2) -- Radius of eye
-
- property kasPrettyEyes : true -- Use 3-D'ish eyes?
-
- property kasColorL : {11111, 33333, 44444} -- Left Iris
- property kasColorR : {11111, 22222, 44444} -- Right Iris
- property kasColorB : {60000, 59000, 58000} -- Eye Ball
- property kasBack : {22222, 22222, 19999}
-
- property kasName : "AkuaEyes V1.0"
-
- global gasWin -- Window
- global gasWinLoc -- Window location
- global gasWinW -- Width of window
- global gasMidXL, gasMidY, gasMidXR -- Midpoint of eyes in global points
- global gasIrisL, gasIrisR -- Local iris bounds
- global gasEyeL, gasEyeR -- Local Eyeball bounds
- global gasEyePic -- Eye Ball Picture
- global gasIrisPicL, gasIrisPicR -- Iris Picture
- global gasIrisRgn -- Region of last iris location
- global gasEyeRgnL, gasEyeRgnR -- Eyeball regions
- global gasMouseLoc -- Last calculated mouse position
-
-
- on run
- pfLoad()
-
- set gasWinW to round (kasEyeSize * 2.25)
- set gasEyeL to {0, 0, kasEyeSize, kasEyeSize}
- set gasEyeR to {gasWinW - kasEyeSize, 0, gasWinW, kasEyeSize}
- set gasMouseLoc to {-1111, -1111}
-
- set gasWin to ¬
- display drawing titled kasName ¬
- with dimensions {gasWinW, kasEyeSize} ¬
- located at gasWinLoc
-
- draw a box into gasWin ¬
- inside of {0, 0, gasWinW, kasEyeSize} ¬
- filling it by erasing it ¬
- using state {bg col64:kasBack}
-
- EyeMidPoints(gasWinLoc)
-
- CreateRgns()
-
- if (kasPrettyEyes) then
- CreateEye()
- CreateIris()
- end if
- end run
-
-
- on quit
- pfSave()
- display drawing gasWin with disposal
- continue quit
- end quit
-
-
- on idle
- repeat with i from 1 to 60
- if EyeCalc() then
- EyesDraw()
- pause for 5 with break on key and break on button
- set i to 1
- end if
- end repeat
-
- return 1
- end idle
-
-
- on EyeMidPoints(winLoc)
- set gasWinLoc to winLoc
-
- set eyeHalf to round (kasEyeSize / 2)
-
- set gasMidY to round (item 2 of gasWinLoc) + eyeHalf
- set gasMidXL to (item 1 of gasWinLoc) + eyeHalf
- set gasMidXR to (item 1 of gasWinLoc) + gasWinW - eyeHalf
- end EyeMidPoints
-
-
- on EyeCalc()
- set mouseLoc to pointer location of (input state)
-
- if (mouseLoc is not gasMouseLoc) then
- set gasMouseLoc to mouseLoc
- set gasIrisL to EyeCalcOne(gasMidXL)
- set gasIrisR to EyeCalcOne(gasMidXR)
- return true
- end if
-
- return false
- end EyeCalc
-
-
- on EyeCalcOne(xp)
- -- Calculate our mid point by triangulation
- set a2 to (item 1 of gasMouseLoc) - xp
- set b2 to (item 2 of gasMouseLoc) - gasMidY
- -- Distance to mouse (hypothenuse of large triangle)
- set c2 to (a2 ^ 2 + b2 ^ 2) ^ 0.5
- -- Proportion of radius (c1) to c2
- set ratio to kasRadI / c2
- -- Scale a1, b1
- set a1 to round (ratio * a2)
- set b1 to round (ratio * b2)
- -- Create box, convert to local coords
- set x1 to xp + a1 - (item 1 of gasWinLoc)
- set y1 to gasMidY + b1 - (item 2 of gasWinLoc)
- return {x1 - kasRadI, y1 - kasRadI, x1 + kasRadI, y1 + kasRadI}
- end EyeCalcOne
-
-
- on EyesDraw()
- -- Map Iris region to left & right iris
- set irisRgnL to calculate region from the mapping ¬
- of region gasIrisRgn inside of gasIrisL
- set irisRgnR to calculate region from the mapping ¬
- of region gasIrisRgn inside of gasIrisR
-
- -- Get left & right eye clips by subtracting the irises from the eyeballs
- set eyeRgnL to calculate region from the difference ¬
- of region gasEyeRgnL ¬
- with region irisRgnL
- set eyeRgnR to calculate region from the difference ¬
- of region gasEyeRgnR ¬
- with region irisRgnR
-
- if (kasPrettyEyes) then
- -- Draw Left Iris
- draw a picture into gasWin ¬
- inside of gasIrisL ¬
- using data gasIrisPicL ¬
- without recording
-
- -- Draw Right Iris
- draw a picture into gasWin ¬
- inside of gasIrisR ¬
- using data gasIrisPicR ¬
- without recording
-
- -- Draw Left Eyeball
- draw a picture into gasWin ¬
- inside of gasEyeL ¬
- clipping to region eyeRgnL ¬
- using data gasEyePic ¬
- without recording
-
- -- Draw Right Eyeball
- draw a picture into gasWin ¬
- inside of gasEyeR ¬
- clipping to region eyeRgnR ¬
- using data gasEyePic ¬
- without recording
- else
- -- Draw Left Iris
- draw an oval into gasWin ¬
- inside of gasIrisL ¬
- filling it with the pen ¬
- using state {fg col64:kasColorL} ¬
- without recording
-
- -- Draw Right Iris
- draw an oval into gasWin ¬
- inside of gasIrisR ¬
- filling it with the pen ¬
- using state {fg col64:kasColorR} ¬
- without recording
-
- -- Draw Left Eyeball
- draw an oval into gasWin ¬
- inside of gasEyeL ¬
- filling it with the pen ¬
- using state {fg col64:kasColorB} ¬
- clipping to region eyeRgnL ¬
- without recording
-
- -- Draw Right Eyeball
- draw an oval into gasWin ¬
- inside of gasEyeR ¬
- filling it with the pen ¬
- clipping to region eyeRgnR ¬
- without recording
- end if
- -- Has window moved?
- set wLoc to screen location of ¬
- (display drawing gasWin)
- if (wLoc is not gasWinLoc) then EyeMidPoints(wLoc)
- end EyesDraw
-
-
- on CreateEye()
- set gasEyePic to CreateBall(kasEyeSize, gasEyeRgnL, kasColorB, 0)
- end CreateEye
-
-
- on CreateIris()
- set gasIrisPicL to CreateBall(kasIrisSize, gasIrisRgn, kasColorL, kasPupilSize)
- set gasIrisPicR to CreateBall(kasIrisSize, gasIrisRgn, kasColorR, kasPupilSize)
- end CreateIris
-
-
- on CreateBall(dim, rgn, col, blackCenter)
- set ballWin to display drawing titled ¬
- "Creating Ball" with dimensions {dim, dim}
-
- set box to {0, 0, dim, dim}
-
- set cnt to round (dim / 3)
-
- copy col to fgc
- set colStepR to round ((65000 - (item 1 of fgc)) / cnt)
- set colStepG to round ((65000 - (item 2 of fgc)) / cnt)
- set colStepB to round ((65000 - (item 3 of fgc)) / cnt)
-
- repeat with i from 1 to cnt
- draw an oval into ballWin ¬
- inside of box ¬
- using state {fg col64:fgc, pen size:{2, 2}}
-
- set item 3 of box to (item 3 of box) - 1
- set item 4 of box to (item 4 of box) - 1
-
- draw an oval into ballWin ¬
- inside of box ¬
- using state {fg col64:fgc, pen size:{1, 1}}
-
- set item 1 of box to (item 1 of box) + 1
- set item 2 of box to (item 2 of box) + 1
- set item 3 of box to (item 3 of box) - 1
- set item 4 of box to (item 4 of box) - 1
-
- set item 1 of fgc to (item 1 of fgc) + colStepR
- set item 2 of fgc to (item 2 of fgc) + colStepG
- set item 3 of fgc to (item 3 of fgc) + colStepB
- end repeat
-
- if (blackCenter is not 0) then
- set d to round ((dim - blackCenter) / 2)
- draw an oval into ballWin ¬
- inside of {d, d, d + blackCenter, d + blackCenter} ¬
- using state {fg col64:{0, 0, 0}} ¬
- filling it with the pen
- end if
-
- set ball to ¬
- capture picture from ballWin ¬
- inside region rgn ¬
- using depth 8 ¬
- with pixel conversion and dithering
-
- display drawing ballWin with disposal
-
- return ball
- end CreateBall
-
-
- on CreateRgns()
- set ballWin to display drawing titled ¬
- "Creating Regions" with dimensions {kasEyeSize, kasEyeSize}
-
- -- Left Eye Region
- set box to {0, 0, kasEyeSize, kasEyeSize}
-
- draw an oval into ballWin ¬
- inside of box
-
- set gasEyeRgnL to capture region from ballWin
-
- -- Basic iris region
- set box to {0, 0, kasIrisSize, kasIrisSize}
-
- draw an oval into ballWin ¬
- inside of box ¬
- with a clear slate
-
- set gasIrisRgn to capture region from ballWin
-
- -- Map left eye region to right eye
- set gasEyeRgnR to calculate region from the mapping ¬
- of region gasEyeRgnL ¬
- inside of gasEyeR
-
- display drawing ballWin with disposal
- end CreateRgns
-
-
- on pfLoad()
- try
- set myPref to load preference named kasName
- on error
- set myPref to {{-1, -1}}
- end try
-
- set gasWinLoc to item 1 of myPref
- end pfLoad
-
-
- on pfSave()
- save preference {gasWinLoc} named kasName
- end pfSave
-